import wx
import pyhk
import thread,time

#run outside of frame class
hot = pyhk.pyhk() 

class Test(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(250, 100))
                
        self.count = 0

        #start with GUI layout

        HotkeyCounterLbl = wx.StaticText(self, wx.ID_ANY, "Hotkey counter:", (20,20))
        self.HotkeyCounter = wx.TextCtrl(self, wx.ID_ANY, "0",(100,20))

        hot.addHotkey(['Ctrl', 'Alt','7'],self.hotkeyFun)
        
    def hotkeyFun(self):
        """Execute when hotkey is pressed"""
        t = ExecFunThread(self)
        t.Start()

class ExecFunThread:
    def __init__(self,frame):
        self.frame = frame

    def Start(self):
        thread.start_new_thread(self.Run, ())

    def Run(self):
        #time consuming function
        time.sleep(10)
        self.frame.count += 1
        self.frame.HotkeyCounter.SetValue(str(self.frame.count))

        

# Run the program
if __name__ == "__main__":
    app = wx.App()
    frame = Test(None, -1, 'Test pyhk in wxpython')
    frame.Show(True)    
    app.MainLoop()

























